<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../global/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
    <link rel="stylesheet" href="../../global/css/ztree/demo.css" type="text/css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form"  enctype="multipart/form-data">
        <fieldset>
            <input type="hidden" id="id" name="id">
            <div class="form-group">
                <label class="col-md-2 control-label">商品</label>
                <div class="col-md-10">
                    <select id="goodsId" class="form-control" name="goodsId">
                    	<option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">秒杀价格</label>
                <div class="col-md-10">
                    <input type="text" class="form-control" placeholder="秒杀价格" name="seckillPrice" id="seckillPrice" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">零钱</label>
                <div class="col-md-10">
                    <input type="text" class="form-control" placeholder="零钱" name="pocketMoney" id="pocketMoney" />
                </div>
            </div>
             <div class="form-group">
                <label class="col-md-2 control-label">秒杀数量</label>
                <div class="col-md-10">
                    <input type="text" class="form-control" placeholder="数量" name="seckillNumber" id="seckillNumber" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">开始时间</label>
                <div class="col-md-10">
                    <input type="text" class="form-control" placeholder="开始时间" name="beginTime" id="beginTime"/>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='skillList.html'">返回</button>
                        <button id="submitbtn" class="btn btn-primary" type="submit" onclick="add()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>

<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/libs/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="../../global/js/my/ztree-menu.js"></script>
<script type="text/javascript">
layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#beginTime'
            ,type: 'datetime'
                ,format: 'yyyy-MM-dd HH:mm:ss'
        });
    });
var id = getUrlParam("id");
    $.ajax({
        type: 'get',
        url: '/clyjSeckillGoods/getGoods',
        data:{id:id},
        contentType: "application/json; charset=utf-8",
        async: false,
        success: function (data) {
        	console.info(data);
        	for(var i=0;i<data.length;i++){
        		$("#goodsId").append("<option value='"+data[i].goodsId+"'>"+data[i].goodsName+"</option>");
        	}
        }
    });
    initData();

    function initData() {
        var id = getUrlParam("id");
        if (id != "") {
            $.ajax({
                type: 'get',
                url: '/clyjSeckillGoods/' + id,
                async: false,
                success: function (data) {
                    $("#goodsId").val(data.goodsId);
                    $("#seckillPrice").val(data.seckillPrice);
                    $("#seckillNumber").val(data.seckillNumber);
                    $("#pocketMoney").val(data.pocketMoney);
                    $("#beginTime").val(data.beginTime);
                }
            });
        }
    }


    $('#form').bootstrapValidator();

    //新增商品
    function add() {
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        $("form").ajaxSubmit({
			 type: 'post',
            url: '/clyjSeckillGoods/saveGoods',
            traditional: true,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                   layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                       location.href = "skillList.html";
                   });
               }
		})

    }

</script>
</body>
</html>